/* created by yanglan on 2008/7/14  FOR OVSD WEB*/  

//????DIV?display,????????????????????????	TR????TR???
//  id?????ID
//  div??????
//  chargeValue:??????????????????????????????

function submitTIME(id){
	var doneTime = new Date();
	document.all(id).value=ChangeTimeToString(doneTime);
	return true;
}

dateFormat='yyyy-mm-dd HH24:mi:ss'
function displayMoreByIdArray(id,chargeValue,div,type){

	var cv1=chargeValue.split("#");
	var cv2=div.split("#");
	for(x=0;x<cv1.length;x++){ 
		DisplayById(id,cv1[x],cv2[x],type);
    }
}
//去掉数组中的重复项
function removeAllrepeat(inStr){
	var objStr = inStr.split(',')
	if(objStr.length<2) return [this[0]]||[]; 
	var arr=[]; 
	for(i=0;i<objStr.length-1;i++){
	  arr.push(objStr.splice(i--,1));
        for(var j=0;j<objStr.length;j++) 
        { 
            if(objStr[j]==arr[arr.length-1]) 
            { 
                objStr.splice(j--,1); 
            } 
        } 
	}
	return arr.join(',');
}

function displayByIdArray(id,chargeValue,div,type){

	var cv=chargeValue.split(",");
	for(x=0;x<cv.length;x++){ 
		if(DisplayById(id,cv[x],div,type)){return true;};
    }
}
	
function DisplayById(id,chargeValue,div,type){

 	var nowValue;
	var s=false;

 	if(type ==1){
	nowValue=document.all(id).value;
	}
	if(type ==2){
	var obj=document.all(id);
	if(obj){
       for(var i=0;i<obj.length;i++){
          if(obj[i].checked){
            nowValue=obj[i].value;
                 break;
          } 
        } 
      } 
	}
	var str=div.split(",");
	for (i=0;i<str.length ;i++ ) {
   	  	if(nowValue == chargeValue){
	  		document.all(str[i]).style.display = 'block';
	  		s=true;
	  	}else{
	  		document.all(str[i]).style.display = 'none';
	  	}
    }
    
    return s;
}


//receive
function getIcurr(loginID,icurractID,itaskID){
	var url='dureIC.do?login_NO='+loginID+'&ITASKID='+itaskID+'&ICURRACTID='+icurractID+'&rondom='+Math.random();
    createXmlHttp();
    xmlHttp.open("GET", url , false);
    xmlHttp.send(null);
	self.location.reload();
	
}

//send
function allotURL(ID,istaffWG,icurractID,itaskID){

 var url='common/getWorkGroup.jsp?ID='+ID+'&istaffWG='+istaffWG+'&ITASKID='+itaskID+'&ICURRACTID='+icurractID+'&rondom='+Math.random();
 newopen = window.open(url,'newwindow','height=250,width=450,top=200,left=300,toolbar=no,menubar=no,scrollbars=no, resizable=no,location=no, status=no');
}

var xmlHttp;
var check;

//创建createXmlHttp；
function createXmlHttp() {
    if (window.XMLHttpRequest) {
       xmlHttp = new XMLHttpRequest();                 
    } else {
       xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
}

//url为调用的地址，select为所要选择的下拉框的ID，changeSelect为要改变的下拉框的ID
function getProblem(url,select,changeSelect) {

    var id=document.getElementById(select).value;
    var type=document.getElementById(changeSelect).value;

    createXmlHttp();
    xmlHttp.open("GET", url+"?id="+id+"&type="+type , false);
    xmlHttp.send(null);

    if (xmlHttp.readyState == 4){
       if (xmlHttp.status == 200){
          var pageInfo = eval("("+xmlHttp.responseText+")");             
          var SelectNode=document.getElementById(changeSelect);
          SelectNode.length=0;
          for(var o in pageInfo){
            SelectNode.appendChild(createSelect(o,pageInfo[o]));
          }
        }else{
          alert("请求页面有异常");
        }
   }
}

function initgetFunc_TIME(url,select,changeSelect,selectValue,HoursValue){
	getFunc_TIME(url,select,changeSelect,selectValue,HoursValue);
}

//url为调用的地址，select为所要选择的下拉框的ID，changeSelect为要改变的时间TEXT的ID
function getFunc_TIME(url,select,changeSelect,selectValue,HoursValue) {

    var id=document.getElementById(select).value;

	var typeValue = selectValue.split(',');
	var typeTime = HoursValue.split(',');
	
	for(i=0;i<typeValue.length;i++){
		if(id==typeValue[i]){
			hours = typeTime[i];
		}
	}

	var doneTime = new Date();
	var timeid = ChangeTimeToString(doneTime);

    createXmlHttp();
    xmlHttp.open("GET", url+"?setTime="+timeid+"&setHours="+hours , false);
    xmlHttp.send(null);

    if (xmlHttp.readyState == 4){
       if (xmlHttp.status == 200){
          var pageInfo = eval("("+xmlHttp.responseText+")");
          var SelectNode=document.getElementById(changeSelect);
          SelectNode.length=0;
          for(var o in pageInfo){
            document.getElementById(changeSelect).value=pageInfo[o];
          }
        }else{
          alert(xmlHttp.status);
        }
   }
}

function createSelect(value,text){
  var opt=document.createElement("option");
  opt.setAttribute("value",value);
  opt.appendChild(document.createTextNode(text));
  return opt;
}


//让所有父节点与当前节点的选择状态一致
function changeParentCheck(srcNode){
 nodeParent = srcNode.parent;
 if (nodeParent.isCheck){
   nodeParent.checkBox.checked = srcNode.checkBox.checked;
   changeParentCheck(nodeParent);
 }
}
//让所有子节点与当前节点的选择状态一致
function changeChildrenCheck(srcNode){
  if (srcNode.hasChild){
    var nodes = srcNode.children;
    var i=0;
    for (i=0;i<nodes.length;i++){
      var node = nodes[i];
      if (node.isCheck){
            node.checkBox.checked = srcNode.checkBox.checked;
            changeChildrenCheck(node);
      }
    }
  }
}



//获取节点的值
function doGetID(treeID,textID){

var obj = document.getElementsByName(treeID); //获取多选框数组
var objLen= obj.length; //获取数组长度
var objYN; //是否有选择
var objValue = new Array();
var i;

for (i = 0;i< objLen;i++){
	if (obj [i].checked==true) {
		if(obj[i].value != ''){
			objValue.push(obj[i].value);
		}
	}	
}
self.opener.document.getElementById(textID).value=objValue.join(',');
}
//获取节点的值
function doGetIDADD(treeID,textID,value){

var obj = document.getElementsByName(treeID); //获取多选框数组
var objLen= obj.length; //获取数组长度
var objYN; //是否有选择
var objValue = new Array();
var i;

for (i = 0;i< objLen;i++){
	if (obj [i].checked==true) {
		if(obj[i].value != ''){
			objValue.push(obj[i].value);
		}
	}	
}
self.opener.document.getElementById(textID).value=value+objValue.join(',');
}

//清空所有节点
function clearAll(treeID){
	var obj = document.getElementsByName(treeID);
	var objLen= obj.length;
	var x=0;
	for (i = 0;i< objLen;i++){
		obj[i].checked=false;	
	}
}


//关闭树型结构的页面
function closeTree(textID){

self.opener.document.getElementById(textID).value=s;
window.opener=null;    
window.open("","_self");   
window.close(); 
}

//检验是否为空
function getIsEmpty(id,mes){
var obj=document.getElementById(id).value;
  obj = obj.trim();
  if(obj==""){
  alert(mes+'不能为空');
  return false;
}else{
  return true;  
  }
}


//检测单选和复选框是否为空
function getRadioEmpty(id,mes){
	var obj=document.all(id);
	if(obj){
       for(var i=0;i<obj.length;i++){
          if(obj[i].checked){
            return true;
            break;
          } 
        } 
      }
    alert(mes+'不能为空');
    return false;
}




//检验包含的字符,返回0为包含非法字符，返回1为全是数字，返回2为包含字母
function getIncludes(id,mes){
  var re1=/[0-9]+/;
  var re3=/\W+/;
  var obj=document.getElementById(id).value;
  
  if(obj.match(re1)==obj){
    return 1;
  }else if(obj.match(re3)!=null){
  	alert(mes+'包含非法字符');
    return 0;
  }else {
    return 2;  
  }
}


//关闭页面并且刷新父页面
function closeAndFlush(){
	self.opener.location.reload();
	window.opener=null;    
	window.open("","_self");   
	window.close(); 
	}
//去掉字串左边的空格
function lTrim(str)
{
if (str.charAt(0) == " "||str.charAt(0) == "　")
{
str = str.slice(1);
str = lTrim(str);
}
return str;
}
//去掉字串右边的空格
function rTrim(str)
{
var iLength;

iLength = str.length;
if (str.charAt(iLength - 1) == " "||str.charAt(iLength - 1) == "　")
{
str = str.slice(0, iLength - 1);
str = rTrim(str); 
}
return str;
}
//去掉字串两边的空格
function trim(str)
{
return lTrim(rTrim(str));
}



//检测隐藏的是否为空
function getHidenEmpty(radioID,id,mes,checkValue,inType){
if(inType=='SELECT'){

	var o=document.getElementById(radioID).value;
	for(var i=0;i<checkValue.length;i++){
	  if(o==checkValue[i]){
		return getIsEmpty(id,mes);
      }
      
	}
	return true;
 }else{	
    var obj=document.all(radioID);
	if(obj){
       for(var i=0;i<obj.length;i++){
          if(obj[i].checked==true&&obj[i].value==checkValue){
				if(inType=='TEXT'){return getIsEmpty(id,mes);}
				if(inType=='RADIO'){return getRadioEmpty(id,mes);}
         	 	if(inType=='SELECT_LR'){
	  				if(obj[i].value==checkValue){
						if(document.all(id).length<1){
							alert(mes+" 不能为空");return false;
						}
					}
				}
          } 
        } 
      }
      return true;
      }
}

//用于验证Textarea文本框长度

function CheckTextareaLength(id,length,desc)
{
     if(document.all(id).value.length >length-1){
     document.all(id).value=document.all(id).value.substr(0,length);
     //document.all(id).disabled="true";
     //alert(desc+"输入内容不能超过"+length+"个字符");
     return false;
     }else{
     return;
     }
}

//级联下拉框和时间TEXT
function timeTextGetSelect(textID,changeSelectID,TimeValue,SelectValue,timeType){


	var obj=document.all(textID);
    var selectID=document.getElementById(changeSelectID).value;
	

	var strTime =TimeValue.split(',');
	var strSelect =SelectValue.split(',');
	
	for(i=0;i<strTime.length;i++){
	  if(strSelect[i]==selectID){
	    var doneTime = changeTime('',strTime[i],timeType);
	    obj.value=ChangeTimeToString(doneTime);
	  }
	}
//	for(j=0;j<obj.length;j++){
//		if(obj[j].checked && obj[j].value == radioValue1){
//			for(var i=0;i<selectID.length;i++){
//				if(selectID[i].value==value1){
//					selectID[i].selected=true;
//				}
//			}
//		}
//		if(obj[j].checked && obj[j].value == radioValue2){
//			for(var i=0;i<selectID.length;i++){
//				if(selectID[i].value==value2){
//					selectID[i].selected=true;
//				}
//				
//			}		
//		}
//	}	
}

//级联下拉框和RADIO
function radioGetSelect(radioID,changeSelectID,radioValue1,value1,radioValue2,value2){

	var obj=document.all(radioID);
    var selectID=document.getElementById(changeSelectID);

	for(j=0;j<obj.length;j++){
		if(obj[j].checked && obj[j].value == radioValue1){
			for(var i=0;i<selectID.length;i++){
				if(selectID[i].value==value1){
					selectID[i].selected=true;
				}
			}
		}
		if(obj[j].checked && obj[j].value == radioValue2){
			for(var i=0;i<selectID.length;i++){
				if(selectID[i].value==value2){
					selectID[i].selected=true;
				}
				
			}		
		}
	}
	getFunc_TIME('setDoneTime.do','column11','column12','紧急,高,中,低','4,8,48,96');
}


//改变设置的时间
function changeTime(set,time,type){

  //设置时间
  if(set==""){
    gNow = new Date();
  }else{
    var gNow = new Date(set.valueOf(Date));
  }

  var gNowTime = gNow.getTime();

  //定义转换单位
  var second = 1000;
  var minutes = second *60;
  var hours=minutes*60;
  var day=hours*24;

  var i=0;

  //当要改变的时间为秒
  if(type=="second"){
    gNowTime +=time*second;
  }

  //当要改变的时间为分钟
  if(type=="minutes"){
    gNowTime +=time*minutes;
  }  

  //当要改变的时间为小时
  if(type=="hours"){
    gNowTime +=time*hours;
  } 

  //当要改变的时间为天
  if(type=="day"){
    gNowTime +=time*day;
  } 


  //当改变的时间为月
  if(type=="month"){
    
    //循环为每月加上固定的天数
    while(time>0){
      var m=gNow.getMonth(set.valueOf(Date));

      //当前设置的月份为4，6，9，11月时加上30天
      if(m==3||m==5||m==8||m==10){
	gNowTime+=day*30;
	gNow.setTime(gNowTime);
	time--;
      }else if(m==1){  
          //当前设置的月份为2月时，当是润年加上29天
	  if((gNow.getYear()%4==0 && gNow.getMonth()%100!=0) || gNow.getMonth()%400==0){
	    gNowTime+=day*29;
	    gNow.setTime(gNowTime);
	    time--;
	  }else{
            gNowTime+=day*28;
	    gNow.setTime(gNowTime);
	    time--;
	  }
	}else{
          //当前设置的月份为1，3，5，7，8，10，12月时加上31天
	  gNowTime+=day*31;
	  gNow.setTime(gNowTime);
	  time--;

          //除去月份之间相差的天数
	  if(gNow.getMonth()==m+1||gNow.getMonth()==m-11){
	  }else{
	    i++;
	    if(gNow.getMonth()==2){
		if((gNow.getYear()%4==0&&gNow.getMonth()%100!=0)||gNow.getMonth()%400==0){
		  i++;
		}else{
		  i+=2;
		}
	    }
         }
	}
    }
    gNowTime-=day*i;
  } 

  //当改变的时间为年，判断闰年
  if(type=="year"){
    while(time>0){
      var y=gNow.getYear();
      if((y%4==0 && y%100!=0) || y%400==0){
	gNowTime+=day*366;
	gNow.setTime(gNowTime);
	time--;
      }else{
	gNowTime+=day*365;
	gNow.setTime(gNowTime);
	time--;
      }
    }
  }  
   gNow.setTime(gNowTime );
 //  alert(gNow.toLocaleString());
   return gNow;
}

//将日期转换为'yyyy-mm-dd HH24:mi:ss'格式

function ChangeTimeToString(DateIn)
{
    var Year=0;
    var Month=0;
    var Day=0;
    var Hour = 0;
    var Minute = 0;
    var Second = 0;
    var CurrentDate="";

    //初始化时间
    Year      = DateIn.getYear();
    Month     = DateIn.getMonth()+1;
    Day       = DateIn.getDate();
    Hour      = DateIn.getHours();
    Minute    = DateIn.getMinutes();
    Second	  = DateIn.getSeconds();

    CurrentDate = Year + "-";
    if (Month >= 10 )
    {
        CurrentDate = CurrentDate + Month + "-";
    }
    else
    {
        CurrentDate = CurrentDate + "0" + Month + "-";
    }
    if (Day >= 10 )
    {
        CurrentDate = CurrentDate + Day ;
    }
    else
    {
        CurrentDate = CurrentDate + "0" + Day ;
    }
    
     if(Hour >=10)
    {
        CurrentDate = CurrentDate + " " + Hour ;
    }
    else
    {
        CurrentDate = CurrentDate + " 0" + Hour ;
    }
    if(Minute >=10)
    {
        CurrentDate = CurrentDate + ":" + Minute ;
    }
    else
    {
        CurrentDate = CurrentDate + ":0" + Minute ;
    }      
    if(Second >=10)
    {
        CurrentDate = CurrentDate + ":" + Second ;
    }
    else
    {
        CurrentDate = CurrentDate + ":0" + Second ;
    }     
    return CurrentDate;
}

/**//*    
    功能：修改 window.setTimeout，使之可以传递参数和对象参数    
    使用方法： setTimeout(回调函数,时间,参数1,,参数n)    
*/    
var __sto = setTimeout;     
window.setTimeout = function(callback,timeout,param){     
    var args = Array.prototype.slice.call(arguments,2);     
    var _cb = function(){     
        callback.apply(null,args);     
    }     
    __sto(_cb,timeout);     
}     

//初始化完成时间    
function initDoneTime(id,timeChange,timeType)
{
	var doneTime = changeTime('',timeChange,timeType);
    document.all(id).value=ChangeTimeToString(doneTime);
}

//初始化结束时间
function initEndTime(id){
	var doneTime = new Date();
    document.all(id).value=ChangeTimeToString(doneTime);
	window.setTimeout(initEndTime,1000,id);
}


function getSelectedOptions(nameSel)
{
	var exOptions = new Array();
	var objs = document.all(nameSel).options
	var count = 0 ;
	for(var i=0;i<objs.length;i++)
	{
		var obj = objs.item(i);
	    if(obj.selected)
	    {
	    	exOptions[exOptions.length]=obj; 
	    }
	}
	return exOptions ;
}

// left right select list change
function exchangeSelect(fromName,toName)
{
	var exOptions = getSelectedOptions(fromName);
	addOptions(exOptions,toName);
	deleteSelected(fromName);
}

// for exchangeSelect
function addOptions(srcOptions,nameSel)
{
	for(var i=0;i<srcOptions.length;i++)
	{
	    var srcOption = srcOptions[i] ;
		var oOption = document.createElement("OPTION");
		oOption.text  = srcOption.text;
		oOption.value = srcOption.value;
		document.all(nameSel).options.add(oOption);
	}
}

//for exchangeSelect
function deleteSelected(nameSel)
{
	var objs = document.all(nameSel);
	for(var i=objs.length-1;i>=0;i--)
	{
		var obj = objs.item(i);
	    if(obj.selected)
	    {
	    	document.all(nameSel).options.remove(i);
	    }
	}
}


function BtnSelect_OnSelectAll(obj){   
		if(obj != null && obj.length > 0 ){
           for(var i=0;i<obj.length;i++){
               obj[i].selected="true";
           }
        }
}


function replaceColummValueBySelected()
{
    var objs = document.getElementsByTagName("select");
      var re = /Selected$/;
      if(objs!=null)
     {
       for(var i=0;i<objs.length;i++)
       {
          if(objs[i].multiple == true )
         {
            var elementid = objs[i].id;
            if(re.test(elementid))
            {
               var lastvalue="";
               var dd = elementid.substr(0,elementid.length-8);
               var e = document.getElementById(dd); 
               for(var j=0;j<objs[i].length;j++)
               {
                  lastvalue = lastvalue + objs[i][j].value + ",";
               }
               e.value = lastvalue.substr(0,lastvalue.length-1);        
            }
         }
       }
    }  
    return true;
}
function intoDateBase(id,TYPE_ID){
	var TYPE_NAME = document.getElementById(id).value;
	if(TYPE_NAME!=''){	
		var url='IntoSolve.do?CONF_TYPE='+TYPE_ID+'&CONF_NAME='+TYPE_NAME+'&rondom='+Math.random();
    	createXmlHttp();
    	xmlHttp.open("GET", url , false);
    	xmlHttp.send(null);
    	alert('信息已插入');
    }else{
    	alert('信息不能插入空值');
    }
}

function DeleteDateBase(id,TYPE_ID){
	var TYPE_NAME = document.getElementById(id).value;
	if(TYPE_NAME!=''){	
		var url='IntoSolve.do?CONF_TYPE='+TYPE_ID+'&CONF_NAME='+TYPE_NAME+'&rondom='+Math.random();
    	createXmlHttp();
    	xmlHttp.open("GET", url , false);
    	xmlHttp.send(null);
    	alert('信息已插入');
    }else{
    	alert('信息不能插入空值');
    }
}

function getNUMEmpty(id,mes){
  if(getIsEmpty(id,mes)){
  	if(getIncludes(id,mes)!=1){
  	  alert(mes+'必须为数字');
  	  return false;
  	}
  	return true;
  }else{
    return false;
  }
}

function submitTITLE(id,mes,columnMes,colunmID,columnType,ifTime){
	var s=mes+':';
	var elementMes = columnMes.split(',');
	var elementID = colunmID.split(',');
	var elementType = columnType.split(',');
	for(x=0;x<elementID.length;x++){ 
	  if(elementType[x]==1){
	    s+=elementMes[x]+document.all(elementID[x]).options[document.all(elementID[x]).selectedIndex].text+',';
	  }else{
	  	s+=elementMes[x]+document.all(elementID[x]).value+',';
	  }
    }
    if(ifTime == 'now'){
		var doneTime = new Date();
		s+='时间'+ChangeTimeToString(doneTime);
	}else{
		s=s.substring(0,s.length-1);
	}
	document.all(id).value = s;
	return true;
}